package com.laborer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laborer.entity.TiantaiStudentNumber;
import com.laborer.mapper.StudentIdManagementMapper;
import com.laborer.model.params.TiantaiStudentNumberParams;
import com.laborer.service.IStudentIdManagementService;
import com.laborer.utils.LayuiPageFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Map;

/**
 * @Auther: Wangym
 * @Date: 2021/9/19 12:21
 * @Description:
 */
@Primary
@Service
public class StudentIdManagementServiceImpl extends ServiceImpl<StudentIdManagementMapper, TiantaiStudentNumber> implements IStudentIdManagementService {

    @Override
    public IPage<Map<String, Object>> findAll(TiantaiStudentNumberParams tiantaiStudentNumberParams) {
        Page pageContext = getPageContext();
        QueryWrapper<TiantaiStudentNumber> wrapper = new QueryWrapper<>();
        if(!ObjectUtils.isEmpty(tiantaiStudentNumberParams.getName())){
            wrapper.eq("name",tiantaiStudentNumberParams.getName());
        }
        if(!ObjectUtils.isEmpty(tiantaiStudentNumberParams.getSex())){
            wrapper.eq("sex",tiantaiStudentNumberParams.getSex());
        }
        if(!ObjectUtils.isEmpty(tiantaiStudentNumberParams.getInCampus())){
            wrapper.eq("in_campus",tiantaiStudentNumberParams.getInCampus());
        }
        return baseMapper.selectMapsPage(pageContext, wrapper);
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
}
